"""
______________________________
time：2021/5/31
______________________________

"""
import unittest
import os
from datetime import datetime

import HwTestReport

from cases import test_case01_supplier, test_case02_purchase_contract
from scripts.handle_path import REPORTS_DIR, CASES_DIR
from scripts.handle_yaml import do_yaml
from scripts.handle_log import do_log

# # 1.创建测试套件
# suite = unittest.TestSuite()
# loader = unittest.TestLoader()
# # 2.加载用例到测试套件
# suite.addTest(loader.loadTestsFromModule(test_case01_supplier))

# 优化：如果cases中有500个测试用例每个都需加载到测试套件中就太累了
# 执行顺序默认按ASCII排序执行，所以想控制执行顺序可以修改case的文件名
suite = unittest.defaultTestLoader.discover(CASES_DIR)  # 第二个参数正则表达式，指定匹配规则，默认test*.py，test开头py结尾

# 3.创建一个测试运行程序对象
report_full_path = do_yaml.read_yaml("report", "name") + "_" + \
                   datetime.strftime(datetime.now(), '%Y%m%d%H%M%S') + \
                   '.html'  # 拼接测试报告名称，带上时间戳，每一次的测试报告都保留
"""优化：把生成的报告放到reports目录下"""
report_full_path = os.path.join(REPORTS_DIR, report_full_path)  # 拼接测试报告地址覆盖原来的
# print("report_full_path是：", report_full_path)

runner = HwTestReport.HTMLTestReport(
    stream=open(report_full_path + '.html', 'wb'),
    verbosity=1,
    title=do_yaml.read_yaml("report", "title"),
    description=do_yaml.read_yaml("report", "description"),
    tester=do_yaml.read_yaml("report", "tester"))

runner.run(suite)

do_log.info("全部用例执行完毕了！！！！！！！！！！！！！！！！！")
